﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Http;

namespace d1Common.WebController
{
    public abstract class ControllerBase : ApiController
    {
        protected abstract DbContext dbContext
        {
            get;
        } 

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (this.dbContext!=null) this.dbContext.Dispose();
            }
            base.Dispose(disposing);
        }
        
        protected void Error(string _msg)
        {
            throw new UserException(_msg);
        }

        protected void Error(string _msg, HttpStatusCode _code)
        {
            throw new UserException(_msg, _code);
        }

        protected void Status(HttpStatusCode _code)
        {
            throw new UserException(_code.ToString() + "错误", _code);
        }
    }
}